<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <script>
      function createXHR() {
        var xhr;
        if (window.XMLHttpRequest) {
          xhr = new XMLHttpRequest();
        } else {
          xhr = new ActiveXObjext('Microsoft.XMLHttp');
        }
        return xhr;
      }
      //get请求
      var ajax = createXHR();
      ajax.open("get", "https://cnodejs.org/api/v1/topics", true);
      // ajax.open("get", "https://cnodejs.org/api/v1/topics?page=2&limit=10", true);

      //post请求
      var ajax = createXHR();
      ajax.open('post', 'https://cnodejs.org/api/v1/topics', true);
      ajax.setRequestHeader('Content-Type', 'application/-www-form-urlencoded'); //默认 可不写
      // ajax.setRequestHeader('Content-Type', 'multipart/form-data'); //带图片等文件
      // ajax.setRequestHeader('Content-type', 'application/json; charset=utf-8'); //编码可写可不写
    </script>
  </body>
</html>
